package com.xiangyu.demo.service;

import com.xiangyu.demo.bean.ServerMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * java类简单作用描述
 *
 * @ProjectName: springboot-demo
 * @Package: com.xiangyu.demo.utils
 * @Description: java类作用描述
 * @Author: 向羽
 * @CreateDate: 2018/2/1 16:58
 * @UpdateUser: 向羽
 * @UpdateDate: 2018/2/1 16:58
 * @UpdateRemark: The modified content
 * @Version: 2.0
 */
@Service
public class WebSocketService {
    private Logger logger = LoggerFactory.getLogger(WebSocketService.class);
    @Autowired
    private SimpMessagingTemplate messageTemplate;
    /**
     * 发送给指定用户
     * @param users
     * @param msg
     */
    public void send2Users(List<String> users, ServerMessage msg) {

        messageTemplate.convertAndSendToUser("test", "/topic/message", msg);

    }

}
